www.gusucode.com > 地方成人教育中心整站源代码 1 > 地方成人教育中心整站源代码 1.0/manage/up/upload.asp

    <!--#include file="upfile_class.asp"-->
<!--#include file="../chkuser.asp"-->
<!--#include file="../../inc/upconfig.asp"-->
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	font-size:12px;
}
-->
</style>
<%
FSPath=Server.mappath("./")'取得当前文件在服务器路径
if Request.QueryString ("Type")="Pic" then
	FileSize=idea_picsize
	UpType=idea_pictype
	FSPath=FSPath&"\..\..\Upload\Image\"
elseif Request.QueryString ("Type")="Soft" then
	FileSize=idea_softsize
	UpType=idea_softtype
	FSPath=FSPath&"\..\..\Upload\DownFiles\"
end if

if Request.QueryString ("action")="update" then
	set upfile=new upfile_class '建立上传对象
		upfile.AllowExt=UpType	'设置上传类型的黑名单
		upfile.GetData (FileSize*1024)   '取得上传数据,限制最大上传10M
		if upfile.isErr then  '如果出错
			select case upfile.isErr
			case 1
			Response.Write "请先选择要上传的文件 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
			case 2
			Response.Write "文件大小超过了限制 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
			end select
		else
			for each formName in upfile.file '列出所有上传了的文件
			set oFile=upfile.file(formname)
			SaveFilename=upfile.AutoSave(formname,FSPath) 
			if upfile.iserr then 
				Response.Write upfile.errmessage
			else
			    if Request.QueryString ("Class")="News" then
					Call SetPic(-1,-1,FSPath&SaveFilename,FSPath&SaveFilename) '生成原始图
					Call SetPic(idea_s10w,idea_s10h,FSPath&SaveFilename,FSPath&"s"&SaveFilename) '生成缩略图
					response.write "<script>parent.document.getElementById(""pic"").value='Upload/Image/"&SaveFilename&"'</script>"
					response.write "<script>parent.document.getElementById(""spic"").value='Upload/Image/"&"s"&SaveFilename&"'</script>"
				elseif Request.QueryString ("Class")="Product" then
					Call SetPic(idea_s3w,idea_s3h,FSPath&SaveFilename,FSPath&SaveFilename) '生成展示缩略图
					Call SetPic(idea_s2w,idea_s2h,FSPath&SaveFilename,FSPath&"l"&SaveFilename) '生成列表缩略图
					Call SetPic(idea_s1w,idea_s1h,FSPath&SaveFilename,FSPath&"s"&SaveFilename) '生成首页缩略图
					response.write "<script>parent.document.getElementById(""pic"").value='Upload/Image/"&SaveFilename&"'</script>"
					response.write "<script>parent.document.getElementById(""lpic"").value='Upload/Image/"&"l"&SaveFilename&"'</script>"
					response.write "<script>parent.document.getElementById(""spic"").value='Upload/Image/"&"s"&SaveFilename&"'</script>"
				elseif Request.QueryString ("Class")="Photo" then
					Call SetPic(-1,-1,FSPath&SaveFilename,FSPath&SaveFilename) '生成展示缩略图
					Call SetPic(idea_s5w,idea_s5h,FSPath&SaveFilename,FSPath&"l"&SaveFilename) '生成列表缩略图
					Call SetPic(idea_s4w,idea_s4h,FSPath&SaveFilename,FSPath&"s"&SaveFilename) '生成首页缩略图
					response.write "<script>parent.document.getElementById(""pic"").value='Upload/Image/"&SaveFilename&"'</script>"
					response.write "<script>parent.document.getElementById(""lpic"").value='Upload/Image/"&"l"&SaveFilename&"'</script>"
					response.write "<script>parent.document.getElementById(""spic"").value='Upload/Image/"&"s"&SaveFilename&"'</script>"
				elseif Request.QueryString ("Class")="Down" then
					Call SetPic(idea_s7w,idea_s7h,FSPath&SaveFilename,FSPath&SaveFilename) '生成展示缩略图
					Call SetPic(idea_s6w,idea_s6h,FSPath&SaveFilename,FSPath&"s"&SaveFilename) '生成首页缩略图
					response.write "<script>parent.document.getElementById(""pic"").value='Upload/Image/"&SaveFilename&"'</script>"
					response.write "<script>parent.document.getElementById(""spic"").value='Upload/Image/"&"s"&SaveFilename&"'</script>"
				elseif Request.QueryString ("Class")="Link" then
					Call SetPic(idea_s8w,idea_s8h,FSPath&SaveFilename,FSPath&SaveFilename) '生成展示缩略图
					response.write "<script>parent.document.getElementById(""pic"").value='Upload/Image/"&SaveFilename&"'</script>"
				elseif Request.QueryString ("Class")="Special" then
					Call SetPic(idea_s9w,idea_s9h,FSPath&SaveFilename,FSPath&SaveFilename) '生成展示缩略图
					response.write "<script>parent.document.getElementById(""pic"").value='Upload/Image/"&SaveFilename&"'</script>"
				elseif Request.QueryString ("Class")="" then
					response.write "<script>parent.document.getElementById(""FileUrl"").value='Upload/DownFiles/"&SaveFilename&"'</script>"
					response.write "<script>parent.document.getElementById(""FileSize"").value='"&Formatnumber(oFile.filesize/1024,2)&"KB'</script>"
				end if
				Response.write "图片上传成功![ <a href=# onclick=history.go(-1)>继续上传</a> ]"
			end if
			set oFile=nothing
			next
		end if
	set upfile=nothing  '删除此对象
else
response.Write "<form id='form' name='form' enctype='multipart/form-data' method='post' action='?action=update&Type="&Request.QueryString ("Type")&"&Class="&Request.QueryString ("Class")&"'>"
response.Write "<input type='file' name='file' />"
response.Write "<input type=submit name=submit value='上传'>"
response.Write "</form>"
end if

Sub SetPic(w,h,opath,spath)
	Set Jpeg = Server.CreateObject("Persits.Jpeg")
		Jpeg.Open opath
		if w<>-1 and h<>-1 then
			'裁出多余部分
			if Jpeg.OriginalWidth / w > Jpeg.OriginalHeight / h then
				Jpeg.Width = Jpeg.OriginalWidth / (Jpeg.OriginalHeight / h)
				Jpeg.Height = Jpeg.OriginalHeight / (Jpeg.OriginalHeight / h)
				Jpeg.Crop (Jpeg.Width-w)/2 , 0 , (Jpeg.Width+w)/2 ,h 
			else
				Jpeg.Width = Jpeg.OriginalWidth / (Jpeg.OriginalWidth / w)
				Jpeg.Height = Jpeg.OriginalHeight / (Jpeg.OriginalWidth / w)
				Jpeg.Crop 0 , (Jpeg.Height-h)/2 , w , (Jpeg.Height+h)/2	
			end if
		else
			Jpeg.Width = Jpeg.OriginalWidth
			Jpeg.Height = Jpeg.OriginalHeight
		end if
		Jpeg.Save spath
		Jpeg.close
	Set Jpeg=nothing
End Sub
%>